/**
 * 
 * @author Lukas Koell
 * @author David Medenjak
 * @author Johannes Riedmann
 */

public abstract class Grosswild extends Animal implements ITrail {

    /**
     * Constructor.
     * @param name Name of the animal.
     */
    public Grosswild(String name) {
        super(name);
    }

    /** grosswild is mounted on a hitch for the transport */
    private Hitch hitch;

    /**
     * hangs an animal to the first free coupling
     * @param couplings
     * @throws Exception
     */
    public boolean hangTo(Hitch[] hitches) {
        
        if (hitch != null) {
            System.out.println("Big animals can only be hanged on once!");
            return false;
        }
        for (int i = 0; i < hitches.length; i++) {
            if (hitches[i] != null) {
                if (hitches[i].getObject() == null) {

                    hitches[i].attachObject(this);
                    return true;
                }
            }
        }
        System.out.println("No free coupling was found for big animal "
                + getName());
        return false;
    }

    /**
     * @return a String representation of the grosswild
     */
    public String list(String prefix) {
        return getName() + " the"
                + this.getClass().toString().replaceAll("class", "");
    }
    
    /**
     * needed for load method to differ between animal and grosswild
     * @param Transporter needed to get reference for hitches
     * @return true on every call (so you know in Transporter class that it's grosswild
     */
    public boolean hangOn(Transporter t) {
        this.hangTo(t.hitches);
        return true;
    }
    
    /**
     * grosswild cannot be unhanged, therefore nothing is going to happen here
     */
    public Trail unHang(){
        return null;
    }
}
